package com.zyw.service;

import com.zyw.domain.CompanyInfo;
import com.zyw.domain.PersonInfo;
import com.zyw.mapper.CompanyInfoMapper;
import com.zyw.mapper.PersonInfoMapper;
import org.activiti.engine.delegate.DelegateExecution;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @Description: 自动服务service
 * @Author: zyw
 * @Date: 2018/5/3
 */
@Service
public class JoinService {

    @Autowired
    private PersonInfoMapper personInfoMapper;
    @Autowired
    private CompanyInfoMapper companyInfoMapper;

    public void joinGroup(DelegateExecution execution){
        Boolean bool = (Boolean) execution.getVariable("joinApproved");
        if (bool) {
            Long personId = (Long) execution.getVariable("personId");
            Long compId = (Long) execution.getVariable("compId");
            CompanyInfo comp = companyInfoMapper.selectByPrimaryKey(compId);
            PersonInfo person = personInfoMapper.selectByPrimaryKey(personId);
            person.setId(comp.getId());
            personInfoMapper.updateByPrimaryKey(person);
            System.out.println("加入组织成功");
        } else {
            System.out.println("加入组织失败");
        }
    }

    //获取符合条件的审批人，演示这里写死，使用应用使用实际代码
    public List<String> findUsers(DelegateExecution execution) {
        return Arrays.asList("admin", "wtr");
    }
}
